﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Buyer
{
    public partial class mfAccountsCentre : msBsc.Cls.mbPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void InitBaseInfo()
        {
            using (msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo objCBizCustomerBaseInfo = new AppLogic.DataAlc.CBizCustomerBaseInfo())
            {
                System.Data.DataSet ds = objCBizCustomerBaseInfo.GetUserAccountInfo();

                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    this.ExecJScript(@"alert(""账户未登录,请先进行登录"");window.location.href=""/mp_UserLogin.htm""");
                    return;
                }

                string totalBalance = ds.Tables[0].Rows[0]["CUSTOMER_DRAWALS_ACCOUNT"] == DBNull.Value ? "0.00" : ds.Tables[0].Rows[0]["CUSTOMER_DRAWALS_ACCOUNT"].ToString();

                string lastDrawalsDt = ds.Tables[0].Rows[0]["CUSTOMER_LAST_DRAWALSDT"] == DBNull.Value ? "该账户暂未提现" : Convert.ToDateTime(ds.Tables[0].Rows[0]["CUSTOMER_LAST_DRAWALSDT"]).ToString("yyyy-MM-dd");

                this.ExecJScript(@"ShowUserAccount('" + totalBalance + "','" + lastDrawalsDt + "')");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "ApplyDrawals")
            {
                ApplyDrawals();
            }

            if (this.strAction == "InitInfo")
            {
                InitBaseInfo();
            }
        }

        private void ApplyDrawals()
        {
            if (!msBsc.SvRef.UserInfo.Online)
            {
                this.ExecJScript("window.location.href='/mp_UserLogin.htm'");
                return;
            }

            string result = string.Empty;

            using (msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo objCBizCustomerBaseInfo = new AppLogic.DataAlc.CBizCustomerBaseInfo())
            {
                result = objCBizCustomerBaseInfo.IsBindDrawalsAccount();
            }

            if (result == "NOUSER")
            {
                this.ExecJScript("alert('当前用户信息有误,请重新登陆');window.location.href='/mp_UserLogin.htm'");
                return;
            }

            if (result == "NOACCOUNNT")
            {
                this.ExecJScript("alert('您还未绑定提现账户，请进行绑定');window.location.href='/mb_BindBalanceInfo.htm'");
                return;
            }

            this.ExecJScript("window.location.href='/mb_ApplyDrawals.htm'");
        }

        
    }
}